<?php

namespace app\tripapi\model;

use think\Model;

use think\Db;

class TravelChatProduct extends Model{
	
    public function TravelChatProductSave($id,$params){
        // 重置checkbox数组下标
        $params['need_verify'] = array_values($params['need_verify']);
        $time = time();
        $number = $params['product_name'];
        foreach($number as $key => $value){
            $data['chat_id'] = $id;
            $data['product_name'] = iconv('UTF-8', 'gbk', $params['product_name'][$key]);
            $data['adhesive'] = iconv('UTF-8', 'gbk', $params['adhesive'][$key]);
            $data['need_num'] = $params['need_num'][$key];
            $data['quota_scale'] = $params['quota_scale'][$key];
            $data['need_verify'] = $params['need_verify'][$key];
            $data['demand'] = iconv('UTF-8', 'gbk', $params['demand'][$key]);
            $data['creator'] = iconv('UTF-8', 'gbk', $params['creator']);
            $data['creator_id'] = $params['creator_id'];
            $data['create_time'] = $time;
            Db::name('travel_chat_product')->insert($data,false,true);
        }
        return true;
    }
    /*
     * 根据id查询删除的明细
     */
    public function ChatProductDelete($id){
        Db::name("travel_chat_product")->where('chat_id', '=', $id)->delete();
        return true;
    }

    public function GetTravelChatProduct($id){
        $result = Db::name('travel_chat_product')->where('chat_id','=', $id)->select();
//        print_r($result);exit;
        return $result;
    }
}

?>